<?php
include_once 'ZCollection.php';

class ZSourceCollection extends ZCollection {
    /**
     * @param $index int Index of ZSourceCollection Array
     * @return ZSourceItem
     */
    public function getIndex($index){
        return $this->items[$index];
    }

    /**
     * @param $item ZSourceItem
     */
    public function addItem($item){
        $this->items[] = $item;
    }

    /**
     * @param $arrThumbSources Array String Thumbnail Sources
     * @param $arrPosts Array int Number of Posts
     * @param $arrAuthors Array int Number of Authors
     * @param $arrThreads Array int Number of Threads
     * @param $top int Select top
     * @param $length int Length of Sources
     */
    public function getTopSources(&$arrThumbSources, &$arrPosts, &$arrAuthors, &$arrThreads, $top, $length){
        for ($i = 0; $i < $top; $i++){
            $item = $this->getIndex($i);

            $sourceName = $item->getSource();
            if (mb_strlen($sourceName, 'UTF-8') > $length){
                $arrThumbSources[] = mb_substr($sourceName, 0, $length, 'UTF-8') . '...';
            }
            else{
                $arrThumbSources[] = $sourceName;
            }

            $arrPosts[] = array(
              'y'           =>      $item->getNumberOfPosts(),
              'fullSource'  =>      $sourceName
            );

            $arrAuthors[] = array(
                'y'           =>      $item->getNumberOfAuthors(),
                'fullSource'  =>      $sourceName
            );

            $arrThreads[] = array(
                'y'           =>      $item->getNumberOfThreads(),
                'fullSource'  =>      $sourceName
            );

        }
    }
}